#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005;

int n,m,st;
vector<LL> edges[N];
LL dist[N];

struct Node{
	int s;
	LL dis;
	bool operator < (const Node& oth) const {
        return dis > oth.dis;
    }
    Node(int s_,LL dis_){
    	s=s_;dis=dis_;
	}
};
int main(){
	scanf("%d%d%d",&n,&m,&st);
	int s;
	LL t,w;
	for(int i=0;i<m;i++){
		scanf("%d%lld%lld",&s,&t,&w);
		edges[s].emplace_back(t);
		edges[s].emplace_back(w);
	}
	priority_queue<Node> que;
	memset(dist,2e9+5L,sizeof(dist));
	dist[st]=0L;
	que.push(Node(st,dist[st]));
	LL curw;
	int size;
	while(!que.empty()){
		s=que.top().s;
		curw=que.top().dis;
		que.pop();
		if(dist[s]<curw) continue;
		size=edges[s].size();
		for(int i=0;i<size;i+=2){
			t=edges[s][i];
			w=edges[s][i+1];
			if(dist[t]>dist[s]+w){
				dist[t]=dist[s]+w;
				que.push(Node(t,dist[t]));
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%lld ",dist[i]);
	}
	return 0;
}
